import {defineStore} from 'pinia'
import {useProgressConfigStore} from './ProgressConfig'
import {usePAUserOneStore} from './PAUserOne'

export const useProjectProgessStore = defineStore('ProjectProgess', {
    state: () => {
        return {
            xAxis: {
                data: []
            },
            yAxis: {},
            series: [
                {
                    data: [],
                    type: 'line',
                    stack: 'x'
                },
                {
                    data: [],
                    type: 'line',
                    stack: 'x'
                },
                {
                    type: 'pie',
                    data: []
                }
            ]
        }
    },
    getters: {},
    actions: {
        clearAll() {
            this.xAxis = {
                data: []
            }
            this.yAxis = {}
            this.series = [
                {
                    data: [],
                    type: 'line',
                    stack: 'x'
                },
                {
                    data: [],
                    type: 'line',
                    stack: 'x'
                },
                {
                    type: 'pie',
                    data: []
                }
            ]
        },
        addAxis() {
            for (let i = 0; i < useProgressConfigStore().tabledata.length; i++) {
                this.xAxis.data.push(useProgressConfigStore().tabledata[i].date)
            }
        },
        addLineSeriesdataOne() {
            this.series[0].data = []
            for (let i = 0; i < useProgressConfigStore().tabledata.length; i++) {
                this.series[0].data.push(useProgressConfigStore().tabledata[i].plan)
            }
        },
        addLineSeriesdataTwo() {
            this.series[1].data = []
            for (let i = 0; i < useProgressConfigStore().tabledata.length; i++) {
                this.series[1].data.push(useProgressConfigStore().tabledata[i].reality)
            }
        },
        count(o) {
            const t = typeof o
            if (t == 'string') {
                return o.length
            } else if (t == 'object') {
                let n = 0
                for (const i in o) {
                    n++
                }
                return n
            }
            return false
        },
        countPieValue() {
            const moth = []
            let flag = 0
            const list = usePAUserOneStore().tabledata
            let wdy = {
                title: '',
                sur_name: []
            }
            for (let i = 0; i < list.length; i++) {
                let az = 0
                for (let j = 0; j < moth.length; j++) {
                    if (moth[j].title == list[i]['position']) {
                        flag = 1
                        az = j
                        break
                    }
                }
                if (flag == 1) {
                    const ab = moth[az]
                    ab.sur_name.push(list[i])
                    flag = 0
                } else if (flag == 0) {
                    wdy = {
                        title: '',
                        sur_name: []
                    }
                    wdy.title = list[i]['position']
                    wdy.sur_name = []
                    wdy.sur_name.push(list[i])
                    moth.push(wdy)
                }
            }
            console.log(moth)
            for (let i = 0; i < moth.length; i++) {
                this.series[2].data.push({
                    value: moth[i].sur_name.length,
                    name: moth[i].title
                })
            }
        }
    }

})
